{include file='public/_header' /}

<link rel="stylesheet" href="/static/lib/editormd/css/editormd.min.css">

<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file='public/_left' /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>&nbsp;文章管理
                    </li>
                    <li>文章编辑</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget radius-bordered">
                            <div class="widget-header bordered-bottom bordered-themeprimary">
                                <span class="widget-caption">文章编辑</span>
                            </div>
                            <div class="widget-body">
                                <form id="form" class="form-horizontal">
                                    <input type="hidden" name="id" value="{$articleInfo.id}">
                                    <div class="form-group">
                                        <label for="title" class="control-label col-sm-1">文章标题</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="title" name="title"
                                                   placeholder="文章标题" value="{$articleInfo.title}"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="cateid" class="control-label col-sm-1">所属导航</label>
                                        <div class="col-sm-6">
                                            <select id="cateid" name="cateid" class="form-control">
                                                <option value="">请选择</option>

                                                {volist name='cates' id='cate'}
                                                    <option value="{$cate.id}" {if $articleInfo.cate_id== $cate.id} selected {/if}>{$cate.catename}</option>
                                                {/volist}

                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="flag" class="control-label col-sm-1">原创标记</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="flag" name="flag"
                                                   placeholder="原创标记" value="{$articleInfo.flag}"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="tags" class="control-label col-sm-1">文章标签</label>
                                        <div class="col-sm-6">
                                            <input type="text" class="form-control" id="tags" name="tags"
                                                   placeholder="文章标签" value="{$articleInfo.tags}"/>
                                            <p class="help-block">多个标签用 | 分割</p>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="checkbox col-sm-offset-1 col-sm-6">
                                            <label>
                                                <input type="checkbox" name="is_top" {if $articleInfo.is_top == 1} checked {/if} value="{$articleInfo.is_top}">
                                                <span class="text">是否推荐</span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="desc" class="control-label col-sm-1">文章概述</label>
                                        <div class="col-sm-6">
                                            <textarea id="desc" name="desc" cols="105" rows="3" placeholder="文章概述">{$articleInfo.desc}</textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="content" class="control-label col-sm-1" style="margin-bottom: 5px;">文章内容</label>
                                        <div id="md-content" style="z-index: 999;">
                                            <textarea id="content" name="content" placeholder="文章内容"
                                                      style="display:none;">{$articleInfo.content}</textarea>
                                        </div>

                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-1 col-sm-1">
                                            <button class="btn btn-primary" id="articleEdit">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file='public/_js' /}

<script src="/static/lib/editormd/editormd.min.js"></script>

<script>
    // 初始化markdown编辑器----------------------
    var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "90%",
            height: 600,
            syncScrolling: "single",
            path: "/static/lib/editormd/lib/"
        });
    });
    //-------------------------------------------

    // 提交编辑
    $('#articleEdit').click(function () {
        $.ajax({
            url: "{:url('admin/article/artedit')}",
            type: 'post',
            dataType: 'json',
            data: $('#form').serialize(),
            success: function (data) {
                if (data.code == 1) {
                    layer.msg('文章编辑成功', {
                        icon: 6,
                        time: 500
                    }, function () {
                        location.href = data.url;
                    });
                } else {
                    layer.open({
                        title: '文章编辑失败',
                        content: data.msg,
                        icon: 5,
                        anim: 6
                    });
                }

            }
        });

        return false;
    });

</script>

</body>
<!--  /Body -->
</html>
